package com.hams.demo.system.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name="t_department")
public class Department {
	
	private Long id;
	private String level;
	private String name;
	private String higherName;
	private String telephone;
	private String address;
	@DateTimeFormat(pattern="yyyy/MM/dd") 
	private Date establish;
	
	private Department parentDepartment;
	private List<Department> childrenDepartments;
	
	private List<User> user;
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}
	
	@JsonIgnore
	@ManyToOne(cascade=CascadeType.ALL)
	public Department getParentDepartment() {
		return parentDepartment;
	}
	
	@JsonIgnore
	@OneToMany(cascade=CascadeType.ALL, mappedBy="parentDepartment", fetch=FetchType.EAGER)
	public List<Department> getChildrenDepartments() {
		return childrenDepartments;
	}
	
	@JsonIgnore
	@OneToMany(mappedBy="department", fetch=FetchType.EAGER)
	public List<User> getUser() {
		return user;
	}

	public String getLevel() {
		return level;
	}
	public String getName() {
		return name;
	}
	public String getHigherName() {
		return higherName;
	}
	public String getTelephone() {
		return telephone;
	}
	public String getAddress() {
		return address;
	}
	
	@JsonFormat(pattern="yyyy/MM/dd", timezone="GMT+8")
	public Date getEstablish() {
		return establish;
	}
	
	public void setId(Long id) {
		this.id = id;
	}
	public void setParentDepartment(Department parentDepartment) {
		this.parentDepartment = parentDepartment;
	}
	public void setChildrenDepartments(List<Department> childrenDepartments) {
		this.childrenDepartments = childrenDepartments;
	}
	public void setLevel(String level) {
		this.level = level;
	}
	public void setName(String name) {
		this.name = name;
	}
	public void setHigherName(String higherName) {
		this.higherName = higherName;
	}
	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public void setEstablish(Date establish) {
		this.establish = establish;
	}
	public void setUser(List<User> user) {
		this.user = user;
	}

}
